#!/bin/bash

echo "=== 重连间隔参数测试 ==="
echo ""

# 测试各种重连间隔值
test_values=(
    "0"      # 低于最小值
    "1"      # 最小值
    "10"     # 默认值
    "30"     # 最大值
    "31"     # 高于最大值
    "abc"    # 非法值
    "5.5"    # 小数
    "-1"     # 负数
)

echo "测试重连间隔参数处理:"
echo "=================="

for value in "${test_values[@]}"; do
    echo "输入值: $value"
    
    # 调用验证函数
    result=$(./vserial_config.sh -c vserial.conf 2>&1 | grep "reconnect_interval" | head -1)
    
    if [ -n "$result" ]; then
        echo "  结果: $result"
    else
        echo "  结果: 使用默认值"
    fi
    echo ""
done

echo "=================="
echo ""

echo "测试模块加载参数:"
echo "=================="

# 测试各种参数值
echo "1. 测试最小值 (0 -> 1):"
echo "sudo insmod vserial_stj.ko reconnect_interval=0"
echo "预期: 警告并调整为1秒"
echo ""

echo "2. 测试最大值 (31 -> 30):"
echo "sudo insmod vserial_stj.ko reconnect_interval=31"
echo "预期: 警告并调整为30秒"
echo ""

echo "3. 测试非法值 (abc -> 10):"
echo "sudo insmod vserial_stj.ko reconnect_interval=abc"
echo "预期: 警告并使用默认值10秒"
echo ""

echo "4. 测试正常值 (15):"
echo "sudo insmod vserial_stj.ko reconnect_interval=15"
echo "预期: 正常使用15秒"
echo "==================" 